package com.fenghongzhang.day018;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class MyAdapter extends BaseAdapter {

    private List<Food.DataBean> list ;
    private Context context;

    public MyAdapter(List<Food.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VH vh;
        if(convertView == null){
                convertView = LayoutInflater.from(context).inflate(R.layout.lv_layout,null);
                vh = new VH();
                vh.lv_img = convertView.findViewById(R.id.lv_img);
                vh.lv_text = convertView.findViewById(R.id.lv_text);
                convertView.setTag(vh);
        }else{
            vh = (VH) convertView.getTag();
        }
            vh = (VH) convertView.getTag();
            vh.lv_text.setText(list.get(position).getTitle());
       return convertView;
    }
    //vh里面是用来缓存findId地址值的,所以,布局文件中,有了那个组件,这个就要加什么组件
    class VH{
        TextView lv_text;
        ImageView lv_img;
    }


}
